from flask import Blueprint,request,jsonify


from db import db1
from utils.acl import acl
from config import get_data
from utils.rs import rs
from utils.jwttoken import jwta
bp_user=Blueprint('bp_user',__name__)

@bp_user.route('/login',methods=['POST'])
def login():
    # username=request.form('username')
    # password=request.form('password')
    data=get_data()
    print(data,111)
    sql="select * from user where username='%s'"%(data['username'])
    res=db1.find(sql)
    password1=res['password']
    if password1==data['password']:
        # data1={"data":{'username':data['username']}}
        data1={'username':data['username']}
        data2=JSON.parse(data1)


        token=jwta.jia_secret(data2)

        # 获取用户页面权限，接口权限
        pagelist=acl.get_page_relist(res['id'])
        interlist=acl.get_interface_relist(res['id'])
        rs.insertdata(interlist)
        return jsonify({'code':200,'token':token,'userid':res['id'],'pagelist':pagelist,'username':res['username']})
    else:
        return jsonify({"code":404})




